package co.fitstart.mobile.entity.trading;

import com.demo2do.core.utils.DateFormatUtils;

import co.fitstart.entity.coupon.Coupon;
import co.fitstart.entity.product.Product;

/**
 * 
 * @author mohanlan
 *
 */
public class CouponMapper {
    
    private Long id;
    
    private String code;
    
    private String type;
    
    private String startDate;
    
    private String endDate;
    
    private String name;
    
    private int amount;
    
    private boolean avaliable;
    
    private boolean onlineYear;
    
    /**
     * The default constructor
     */
    public CouponMapper() {
        
    }
    
    /**
     * 
     * @param coupon
     * @param product
     */
    public CouponMapper(Coupon coupon, Product product) {
        this.id = coupon.getId();
        this.code = coupon.getCode();
        this.startDate = DateFormatUtils.format(coupon.getEffectiveStartDate(),"yyyy-MM-dd");
        this.endDate = DateFormatUtils.format(coupon.getEffectiveEndDate(),"yyyy-MM-dd");
        this.name = coupon.getBatchName();
        this.amount = coupon.getAmount() == null ? 0 : coupon.getAmount();
        this.type = coupon.getType().getDescription();
        if (!coupon.isAvaliable()) {
            this.avaliable = false;
        } else if(coupon.getType().isProduct() && coupon.getTemplate().getProduct().getId() != product.getId()) {
            this.avaliable = false;
        } else if(coupon.getType().isCategory() && !coupon.getTemplate().getProductType().equals(product.getType())) {
            this.avaliable = false;
        } else {
            this.avaliable = true;
        }
        this.onlineYear = coupon.getTemplate().getDiscountType().isPercent();
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * @return the type
     */
    public String getType() {
        return type;
    }

    /**
     * @return the startDate
     */
    public String getStartDate() {
        return startDate;
    }

    /**
     * @return the endDate
     */
    public String getEndDate() {
        return endDate;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the amount
     */
    public int getAmount() {
        return amount;
    }

    /**
     * @return the avaliable
     */
    public boolean isAvaliable() {
        return avaliable;
    }

    /**
     * @return the isOnlineYear
     */
    public boolean isOnlineYear() {
        return onlineYear;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param code the code to set
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * @param type the type to set
     */
    public void setType(String type) {
        this.type = type;
    }

    /**
     * @param startDate the startDate to set
     */
    public void setStartDate(String startDate) {
        this.startDate = startDate;
    }

    /**
     * @param endDate the endDate to set
     */
    public void setEndDate(String endDate) {
        this.endDate = endDate;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param amount the amount to set
     */
    public void setAmount(int amount) {
        this.amount = amount;
    }

    /**
     * @param avaliable the avaliable to set
     */
    public void setAvaliable(boolean avaliable) {
        this.avaliable = avaliable;
    }

    /**
     * @param isOnlineYear the isOnlineYear to set
     */
    public void setOnlineYear(boolean onlineYear) {
        this.onlineYear = onlineYear;
    }
}
